﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using pcceftaw.Models;
using pcceftaw.MembershipRoleProvider;

namespace pcceftaw.Controllers
{ 
    [Authorize]
    [Filtro(Roles = "Administrador")]
    public class PermissoesController : Controller
    {
        private DBContainer db = new DBContainer();

        //
        // GET: /Permissoes/
        
        public ViewResult Index()
        {
            return View(db.seg_tb_permissoes.ToList());
        }

        //
        // GET: /Permissoes/Details/5

        public ViewResult Details(int id)
        {
            seg_tb_permissoes seg_tb_permissoes = db.seg_tb_permissoes.Single(s => s.id_permissao == id);
            return View(seg_tb_permissoes);
        }

        //
        // GET: /Permissoes/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Permissoes/Create

        [HttpPost]
        public ActionResult Create(seg_tb_permissoes seg_tb_permissoes)
        {
            if (ModelState.IsValid)
            {
                db.seg_tb_permissoes.AddObject(seg_tb_permissoes);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(seg_tb_permissoes);
        }
        
        //
        // GET: /Permissoes/Edit/5
 
        public ActionResult Edit(int id)
        {
            seg_tb_permissoes seg_tb_permissoes = db.seg_tb_permissoes.Single(s => s.id_permissao == id);
            return View(seg_tb_permissoes);
        }

        //
        // POST: /Permissoes/Edit/5

        [HttpPost]
        public ActionResult Edit(seg_tb_permissoes seg_tb_permissoes)
        {
            if (ModelState.IsValid)
            {
                db.seg_tb_permissoes.Attach(seg_tb_permissoes);
                db.ObjectStateManager.ChangeObjectState(seg_tb_permissoes, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(seg_tb_permissoes);
        }

        //
        // GET: /Permissoes/Delete/5
 
        public ActionResult Delete(int id)
        {
            seg_tb_permissoes seg_tb_permissoes = db.seg_tb_permissoes.Single(s => s.id_permissao == id);
            return View(seg_tb_permissoes);
        }

        //
        // POST: /Permissoes/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            seg_tb_permissoes seg_tb_permissoes = db.seg_tb_permissoes.Single(s => s.id_permissao == id);
            db.seg_tb_permissoes.DeleteObject(seg_tb_permissoes);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}